<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="/ordermaker/pages/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    #include("common.html")

    <div class="layui-body">
        <div style="margin-left: 10px;margin-right: 10px;margin-top: 15px;">
            <table class="layui-hide" id="test" lay-filter="test"></table>
            <button type="button" class="layui-btn" id="uploadFile">
                <i class="layui-icon">&#xe67c;</i>上传录课时间
            </button>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>
<script src="/ordermaker/pages/layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['element','table','upload'], function(){
        var element = layui.element;
        var table = layui.table;
        var tableIns=table.render({
            elem: '#test'
            ,url:'/ordermaker/admin/luke/list'
            ,title: '录课时间表'
            ,cols: [[
                {field:'jieci', title:'节次'}
                ,{field:'xingqi1', title:'星期一', edit: 'text'}
                ,{field:'xingqi2', title:'星期二', edit: 'text'}
                ,{field:'xingqi3', title:'星期三', edit: 'text'}
                ,{field:'xingqi4', title:'星期四', edit: 'text'}
                ,{field:'xingqi5', title:'星期五', edit: 'text'}
            ]]
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res)
                return {
                    "code": res.erro, //解析接口状态
                    "count": res.datas.totalRow, //解析数据长度
                    "data": res.datas.list //解析数据列表
                };
            }
            ,page: false
        });
        //监听单元格编辑
        table.on('edit(test)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layui.jquery.ajax({
                url: "/ordermaker/admin/luke/edt",
                type: 'post',//method请求方式，get或者post
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                xhrFields:{
                    withCredentials:true
                },
                dataType: 'json',//预期服务器返回的数据类型
                data: data,//表格数据序列化
                success: function (res) {//res为相应体,function为回调函数
                    console.log(res);
                    switch (field) {
                        case 'xingqi1':layer.msg("星期一第"+data.jieci+"节数据已修改为"+value);break;
                        case 'xingqi2':layer.msg("星期二第"+data.jieci+"节数据已修改为"+value);break;
                        case 'xingqi3':layer.msg("星期三第"+data.jieci+"节数据已修改为"+value);break;
                        case 'xingqi4':layer.msg("星期四第"+data.jieci+"节数据已修改为"+value);break;
                        case 'xingqi5':layer.msg("星期五第"+data.jieci+"节数据已修改为"+value);break;
                    }
                    tableIns.reload();
                },
                error: function (res) {
                    console.log(res);
                    layer.alert('操作失败！！！', {icon: 5});
                }
            });
        });
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#uploadFile' //绑定元素
            ,url: '/ordermaker/admin/luke/upload' //上传接口
            ,accept: 'file' //普通文件
            ,exts: 'xls|xlsx' //只允许上传压缩文件
            ,done: function(res){
                if(res.erro==0){
                    layer.msg(res.msg+'条数据导入成功');
                    tableIns.reload();
                }
            }
            ,error: function(){
                //请求异常回调
                layer.alert('导入数据失败,插件异常',{
                    icon: 5
                });
            }
        });
    });
</script>
</body>
</html>